2 Problema: E Parking lot
6 Sebastían Arcila - Andrés Mejía
21 carro(int ID
, int Donde
, bool Parked
){
30 //fstream cin("parking.in");
32 //cout << "Lei casos: " << casos << endl;
33 bool primerCaso
= true;
37 if (!primerCaso
) cout
<< endl
;
40 while (cin
>> id
&& id
!= 99){
41 //cout << "Lei id: " << id << endl;
42 carros
.push_back(carro(id
, id
, false));
45 /*cout << "Voy a imprimir carros:" << endl;
46 for (int i=0; i<carros.size(); ++i){
47 cout << carros[i].id << "-"<<carros[i].donde<<endl;
52 while (getline(cin
, line
) && line
!= ""){
53 stringstream
ss(line
);
56 //cout << "Lei salio: " << salio << endl;
58 int posClosest
= 9999;
59 int minDistance
= 9999;
60 for (int i
=0; i
<carros
.size(); ++i
){
62 if (!carros
[i
].parked
){
64 if (carros
[i
].donde
<= salio
){
65 d
= salio
- carros
[i
].donde
;
67 d
= (salio
+20) - carros
[i
].donde
;
75 //cout << "minDistance es " << minDistance << endl;
76 //cout << "PosClosest es " << posClosest << endl;
77 if (posClosest
== 9999) continue;
78 carros
[posClosest
].parked
= true;
79 carros
[posClosest
].donde
= salio
;
81 for (int i
=0; i
<carros
.size(); ++i
){
82 if (!carros
[i
].parked
){
83 int d
= carros
[i
].donde
+ minDistance
;
84 while (d
> 20) d
-= 20;
89 /*cout << "Voy a imprimir carros:" << endl;
90 for (int i=0; i<carros.size(); ++i){
91 cout << carros[i].id << "-"<<carros[i].donde<<endl;
94 for (int i
=0; i
<carros
.size(); ++i
){
95 cout
<< "Original position " << carros
[i
].id
<< " ";
96 if (carros
[i
].parked
){
97 cout
<< "parked in " << carros
[i
].donde
<< endl
;
99 cout
<< "did not park" << endl
;